

#include "pf_math.h"

void UI_DlgMoveRotate::init() {
    PF_SETTINGS->beginGroup("/Modify");
    copies = PF_SETTINGS->readEntry("/MoveRotateCopies", "10");
    numberMode = PF_SETTINGS->readNumEntry("/MoveRotateMode", 0);
    useCurrentLayer =
        (bool)PF_SETTINGS->readNumEntry("/MoveRotateUseCurrentLayer", 0);
    useCurrentAttributes =
        (bool)PF_SETTINGS->readNumEntry("/MoveRotateUseCurrentAttributes", 0);
    angle = PF_SETTINGS->readEntry("/MoveRotateAngle", "0.0");
    PF_SETTINGS->endGroup();

    switch (numberMode) {
    case 0:
        rbMove->setChecked(true);
        break;
    case 1:
        rbCopy->setChecked(true);
        break;
    case 2:
        rbMultiCopy->setChecked(true);
        break;
    default:
        break;
    }
    leNumber->setText(copies);
    leAngle->setText(angle);
    cbCurrentAttributes->setChecked(useCurrentAttributes);
    cbCurrentLayer->setChecked(useCurrentLayer);
}

void UI_DlgMoveRotate::destroy() {
    PF_SETTINGS->beginGroup("/Modify");
    PF_SETTINGS->writeEntry("/MoveRotateCopies", leNumber->text());
    if (rbMove->isChecked()) {
        numberMode = 0;
    } else if (rbCopy->isChecked()) {
        numberMode = 1;
    } else {
        numberMode = 2;
    }
    PF_SETTINGS->writeEntry("/MoveRotateMode", numberMode);
    PF_SETTINGS->writeEntry("/MoveRotateAngle", leAngle->text());
    PF_SETTINGS->writeEntry("/MoveRotateUseCurrentLayer",
                            (int)cbCurrentLayer->isChecked());
    PF_SETTINGS->writeEntry("/MoveRotateUseCurrentAttributes",
                            (int)cbCurrentAttributes->isChecked());
    PF_SETTINGS->endGroup();
}

void UI_DlgMoveRotate::setData(PF_MoveRotateAttribute* d) {
    data = d;

    leAngle->setText(QString("%1").arg(PF_Math::rad2deg(data->angle)));
}

void UI_DlgMoveRotate::updateData() {
    if (rbMove->isChecked()) {
        data->number = 0;
    } else if (rbCopy->isChecked()) {
        data->number = 1;
    } else {
        data->number = leNumber->text().toInt();
    }
    data->angle = PF_Math::deg2rad(PF_Math::eval(leAngle->text()));
    data->useCurrentAttributes = cbCurrentAttributes->isChecked();
    data->useCurrentLayer = cbCurrentLayer->isChecked();
}

